<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="Keywords" content="" />
    <meta name="Description" content="" />
    <title></title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      .bg {
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
        width: 100%;
        height: 100vh;
        background-image: url('images/0.jpg');
        background-attachment: fixed;
        background-position: -50px 0;
        background-size: 120% 100%;
      }

      ul,
      ol,
      li {
        list-style: none;
      }

      .web {
        position: fixed;
        top: -127px;
        left: 0;
        width: 100%;
        height: 127px;
        line-height: 127px;
        text-align: center;
        /* border: 1px solid #ddd; */
        background: rgba(255, 255, 255, 0.86);
        transition: all 1s ease;
      }

      .web ul {
        width: 928px;
        overflow: hidden;
        display: inline-block;
        vertical-align: middle;
      }

      .web ul li {
        position: relative;
        width: 138px;
        height: 76px;
        line-height: 76px;
        float: left;
        margin-right: 20px;
      }

      .web ul li:hover:after {
        /* 可以获取li上的自定义元素的属性的值 */
        content: attr(data-title);
        position: absolute;
        left: 0;
        top: 0;
        z-index: 520;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.5);
        width: 138px;
        height: 76px;
      }

      .web ul li:last-child {
        margin-right: 0;
      }

      .web ul li img {
        width: 138px;
        height: 76px;
      }

      .tips {
        width: 30px;
        height: 30px;
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background: url('images/tips.png') -94px -4px;
        z-index: 1314;
      }

      .button {
        width: 36px;
        height: 56px;
        position: absolute;
        top: 0;
        left: 20px;
        background: url('images/button.png');
        z-index: 10;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <div
        class="bg"
        :style="{'background-image': `url(images/${bgIndex}.jpg)`}"
      ></div>
      <div class="button" id="toggle" @click="isShow=!isShow"></div>
      <div class="web" id="web" :style="{top: isShow?0: '-127px' }">
        <ul id="nav-list">
          <li
            v-for="(item,index) in list"
            :data-title="item.title"
            :key="item.id"
            @click="handleClick(index)"
            @mouseover="handleMouseover(index)"
            @mouseout="handleMouseout"
          >
            <span :class="{tips: index === active}"></span>
            <img :src="item.src" />
          </li>
        </ul>
      </div>
    </div>

    <script src="./libs/vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          isShow: true,
          active: 0,
          bgIndex: 0,
          list: [
            {
              id: 0,
              src: './images/0.jpg',
              title: '你'
            },
            {
              id: 1,
              src: './images/1.jpg',
              title: '是'
            },
            {
              id: 2,
              src: './images/2.jpg',
              title: '最'
            },
            {
              id: 3,
              src: './images/3.jpg',
              title: '棒'
            },
            {
              id: 4,
              src: './images/4.jpg',
              title: '的'
            },
            {
              id: 5,
              src: './images/5.jpg',
              title: '!'
            }
          ]
        },
        methods: {
          handleClick(index) {
            // console.log(index)
            // 设置点击的选中效果,同时保存了选中的id
            this.bgIndex = this.active = index
          },
          handleMouseover(index) {
            this.bgIndex = index
          },
          handleMouseout() {
            this.bgIndex = this.active
          }
        }
      })
    </script>
  </body>
</html>
